#ifndef _xmltools_h_
#define _xmltools_h_

// xmltools.h
//
// XML tools
//
// This is not close to an XML parser. We did not want to be 
// dependent on an XML parser because we are in control of the
// format and a full parser can get pretty big.


#include "wideTools.h"

#include <string>

namespace simple{
    //
    // XMLTools
    //

    struct XMLElement
    {
        std::wstring name;
        std::wstring value;
    };


    class XMLTools
    {
    public:
        XMLTools ();
        // Initialize our xml "parser" for generating xml

        XMLTools (const std::wstring& xml, WideTools::eBOM endian);
        // Initialize our "parser" with a string (which might be very big)
        // and the endian-ness of the data. If this endian does not match
        // the system value, the string is swapped in place before
        // processing.

        const std::wstring& xml    () const { return _xml;}
        WideTools::eBOM     endian () const { return _endian;}

        XMLElement parse ();
        // Parse and return the next element, which can consist of
        // many other elements. Removes the returned information
        // from _xml.

        std::wstring parseNextTag    ();
        // Returns the next element found, or "" if none

        std::wstring parseNextEndTag (std::wstring tag);
        // Returns the data between the specified element
        // Call after parseNextTag()

        std::wstring parseTag (const std::wstring& start, 
                               const std::wstring& stop);
        // Return the elements between the start and stop elements
        // The parsed data is removed from _xml.

        void writeResource (unsigned int id,
                            const std::wstring& str,
                            const std::wstring& notes);
        // Write this resource information to our internal string.
        // Header information is added if this is our first write.

        void writeTrailing ();
        // Write trailing information for our internal string. Called
        // after writeResource()

    private:
        std::wstring    _xml;     // The string we are parsing (or writing)
        WideTools::eBOM _endian;  // Endian-ness of the data


    };
}

#endif // _xmltools_h_
